﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using EnvDTE;
using FanaticToy.Core.AnaemiaExtractor;
using FanaticToy.Core.CosntructorCloner;

namespace FanaticToy.CommandCore
{
    ///<summary>提取贫血模型。</summary>
    public class ExtractAnaemiaModel
    {
        public void Execute(DTE dte)
        {
            try
            {
                ExecuteCore(dte);
            }
            catch (System.Exception ex)
            {
                Clipboard.SetText($@"/*
{ex.Message}
*/");
            }
        }

        public void ExecuteCore(DTE dte)
        {
            var extractor = new Extractor();
            var documentPath = GetDocumentPath(dte);
            var modelText = extractor.Extract(documentPath);
            if (string.IsNullOrWhiteSpace(modelText)) { Clipboard.SetText("// modelText not found"); return; }
            Clipboard.SetText(modelText);
        }

        private string GetDocumentPath(DTE dte)
        {
            var activeDocument = dte.ActiveDocument;
            return activeDocument.FullName;
        }
    }
}
